﻿using System.Linq;
using Ah.Testudin.Engine.Actors;
using Ah.Testudin.Engine.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Ah.Testudin.Engine.UI.Elements.Debugging
{
    public class ActorCountScreenElement : ScreenElementBase
    {
        #region Private Member Variables

        private readonly GetAllActorsDelegate _getAllActorsDelegate;

        private readonly ITestudinRenderer _renderer;

        private readonly SpriteFont _spriteFont;

        private int _currentActorCount;

        #endregion

        #region Constructors

        public ActorCountScreenElement(
            Vector2 position,
            int width,
            int height,
            GetAllActorsDelegate getAllActorsDelegate,
            ITestudinRenderer testudinRenderer,
            SpriteFont spriteFont)
            :base(position, width, height)
        {
            _getAllActorsDelegate = getAllActorsDelegate;

            _renderer = testudinRenderer;

            _spriteFont = spriteFont;

            _currentActorCount = 0;
        }

        #endregion

        #region ScreenElementBase

        public override short ZOrder
        {
            get { return 1; }
        }

        public override bool Visible
        {
            get { return true; }
        }

        public override bool ProcessInput()
        {
            return false;
        }

        public override void Update(GameTime gameTime)
        {
            _currentActorCount = _getAllActorsDelegate().Count();
        }

        public override void Render()
        {
            _renderer.BeginSpriteBatch();

            _renderer.RenderString(
                _spriteFont,
                string.Format(
                    " - Actors: {0}",
                    _currentActorCount),
                _position,
                Color.Yellow);

            _renderer.EndSpriteBatch();
        }

        #endregion
    }
}
